// ----------------------------
//     // // /    //   // // //
//    //         //   //
//   // //      //   // // //
//        //   //   //      //
//       //   //    //      //
// // //     //      // // //
// ----------------------------
// -           tool           -
// ----------------------------
(function(ב) {
    // 开启严格模式
    "use strict";

    // obj空值
	ב.isEmptyObject = function(e) {
	    var t;
	    for (t in e)
	        return !1;
	    return !0
	}

	//去重
	ב.toHeavy = function(Arrs) {
	    var newArrs = [], json = {};
	    for (var x = 0; x < Arrs.length; x++) {
	        if (!json[Arrs[x]]) {                   //判断是否为undefined
	            if (Arrs[x] == null) {              //空值时赋值
	                Arrs[x] = '';
	            }
	            newArrs.push(Arrs[x]);
	            json[Arrs[x]] = 1;                  //为undefined时给予赋值
	        }
	    }
	    return newArrs;
	}
	
	Array.prototype.remove = function(from, to) {
		var rest = this.slice((to || from) + 1 || this.length);
		this.length = from < 0 ? this.length + from : from;
		return this.push.apply(this, rest);
	};

	// 弹窗
	ב.confirms = (type, content, time) => {
		// 判断类型
		let title = "";
		if (type == "alert") {
			title = "提醒";
		} else if (type == "toast") {
			title = "提醒";
		} else if (type == "confirm") {
			title = "操作提醒";
		} else if (type == "prompt") {
			title = "";
		} else {
			console.log("弹窗类型未找到或未定义！");
			return;
		}

		// 创建单例弹窗
		let confirm = document.createElement("div"),
			confirmBox = document.createElement("div"),
			random = Math.floor(0 + Math.random() * (999 - 0));
		confirm.setAttribute("class", "confirm confirm_"+ random);
		confirmBox.setAttribute("class", "confirmBox");

		// 创建弹窗内容
		let confirmHead = document.createElement("div"),
			confirmMain = document.createElement("div"),
			confirmFoot = document.createElement("div");
		confirmHead.setAttribute("class", "confirmHead");
		confirmMain.setAttribute("class", "confirmMain");
		confirmFoot.setAttribute("class", "confirmFoot");

		// 弹窗顶部
		let confirmHeadTitle = document.createElement("h"),
			confirmHeadTitles = document.createTextNode(title),
			confirmHeadClose = document.createElement("i");
		confirmHeadClose.setAttribute("class", "fa fa-close confirm_close");
		confirmHeadClose.setAttribute("claria-hidden", "true");
		confirmHeadTitle.appendChild(confirmHeadTitles);
		confirmHead.appendChild(confirmHeadTitle);
		confirmHead.appendChild(confirmHeadClose);

		// 弹窗内容
		let confirmMainTitle = document.createTextNode(content);
		confirmMain.appendChild(confirmMainTitle);

		// 弹窗底部
		if (type == "alert") {
			let btn = document.createElement("button"),
				btnTitle = document.createTextNode("确定");
			btn.setAttribute("class", "confirm_btn confirm_defind");
			btn.appendChild(btnTitle);
			confirmFoot.appendChild(btn);
		} else if (type == "toast") {
			
		} else if (type == "confirm") {
			let btn = document.createElement("button"),
				btnTitle = document.createTextNode("取消"),
				btn1 = document.createElement("button"),
				btnTitle1 = document.createTextNode("确定");
			btn.setAttribute("class", "confirm_btn confirm_cancel");
			btn1.setAttribute("class", "confirm_btn confirm_defind");
			btn.appendChild(btnTitle);
			btn1.appendChild(btnTitle1);
			confirmFoot.appendChild(btn);
			confirmFoot.appendChild(btn1);
		} else if (type == "prompt") {
			
		}

		confirmBox.appendChild(confirmHead);
		confirmBox.appendChild(confirmMain);
		confirmBox.appendChild(confirmFoot);
		confirm.appendChild(confirmBox);
		document.body.appendChild(confirm);

		// 弹窗事件
		let confirmx = document.getElementsByClassName("confirm_"+ random),
			closeOpt = document.getElementsByClassName("confirm_close"),
			buttonOpt = document.getElementsByClassName("confirm_btn");

		for (let x = 0; x < closeOpt.length; x++) {
			closeOpt[x].onclick = (e) => {
				e.target.parentNode.parentNode.parentNode.remove();
			}
		}
		
		for (let x = 0; x < buttonOpt.length; x++) {
			buttonOpt[x].onclick = (e) => {
				e.target.parentNode.parentNode.parentNode.remove();
			}
		}

		if (type == "toast" && time != "") {
			setTimeout(function() {
				confirmx[0].remove();
			}, time);
		}
	}

	// 时间类
	// 当前时间
	ב.getTime = function(type) {
	    var date = new Date(),
	        seperator1 = "",
	        seperator2 = "",
	        seperator3 = "",
	        month = date.getMonth() + 1,
	        strDate = date.getDate(),
	        currentdate = null;
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 1 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    if (type == "zh-cn") {
	        seperator1 = "年";
	        seperator2 = "月";
	        seperator3 = "日";
	        currentdate = date.getFullYear() + seperator1 + month + seperator2 + strDate + seperator3;
	    } else if (type == "minusSign") {
	        seperator1 = "-";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    } else if (type == "comma") {
	        seperator1 = ",";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    } else if (type == "slash") {
	        seperator1 = "/";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    } else if (type == "" || type == null || type == undefined) {
	        seperator1 = "";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    }
	    return currentdate;
	}

	ב.getTimex = function(date, type) {
	    var seperator1 = "",
	        seperator2 = "",
	        seperator3 = "",
	        month = date.getMonth() + 1,
	        strDate = date.getDate(),
	        currentdate = null;
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 1 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    if (type == "zh-cn") {
	        seperator1 = "年";
	        seperator2 = "月";
	        seperator3 = "日";
	        currentdate = date.getFullYear() + seperator1 + month + seperator2 + strDate + seperator3;
	    } else if (type == "minusSign") {
	        seperator1 = "-";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    } else if (type == "" || type == null || type == undefined) {
	        seperator1 = "";
	        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	    }
	    return currentdate;
	}

	// 获取年月
	ב.getTimeYD = function(time) {
	    var month = time.getMonth() + 1,
	        currentdate = "";
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    currentdate = time.getFullYear() + "-" + month;
	    return currentdate;
	}

	// 时间变化 - 增加时间
	ב.addDays = function(getTime, number) {
		getTime = getTime.replace(new RegExp("-","gm"),"/");
		getTime = (new Date(getTime)).getTime();
	    var adjustDate = new Date(getTime + 24*60*60*1000*number);
	    return adjustDate;
	}

	// 时间变化 - 减少时间
	ב.lessDays = function(getTime, number) {
	    getTime = getTime.replace(new RegExp("-","gm"),"/");
	    getTime = (new Date(getTime)).getTime();
	    var adjustDate = new Date(getTime - 24*60*60*1000*number);
	    return adjustDate;
	}

	// 转毫秒
	ב.millisecond = function(time) {
	    var time = time,
	        time = time.replace(new RegExp("-","gm"),"/"),
	        time = (new Date(time)).getTime();
	    return time;
	}
})(onemap);